﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Handrise.CDCable.Mobile.Business;
using HandRise.MBHOP.Controls;

namespace Handrise.CDCable.Mobile.UI
{
    public partial class FrmFlawReject :FrmBase
    {
        private Flaw flaw = null;
        private FlawService flawService = new FlawService();

        public FrmFlawReject()
        {
            InitializeComponent();
            ttlbrhead.Text = ResourceImage.巡视管理;
            ilstbcup.Images.Add(ResourceImage.保存01);
            ilstbcup.Images.Add(ResourceImage.键盘01);
            ilstbcup.Images.Add(ResourceImage.返回01);
            ilstdown.Images.Add(ResourceImage.保存02);
            ilstdown.Images.Add(ResourceImage.键盘02);
            ilstdown.Images.Add(ResourceImage.返回02);
        }

        private void FrmFlawReject_Load(object sender, EventArgs e)
        {
            if (IsReturn)
                LoadCacheData();
            else
                LoadData();

            tbTitle.Text = flaw.Title;
            tbRejectReason.Text = flaw.RejectReason;
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            flaw = (Flaw)Parameter[0];
        }

        /// <summary>
        /// 加载缓存数据
        /// </summary>
        private void LoadCacheData()
        {
            flaw = (Flaw)Caches[0];

        }

        private void bcOperate_OnButtonClick(object sender, int buttonIndex)
        {
            switch (buttonIndex)
            {
                case 0:  //保存
                    if(SaveFlawRejectReason())
                        mssdlgConfirm.ShowDialog(this, "保存成功", DialogType.Confirm, FormManage.form_Deactivate);
                    break;
                case 1:  //键盘
                    InputMethod.SHFullScreen(this.Handle, 4);
                    InputMethod.SipShowIM(1);
                    break;
                case 2:  //返回
                    FormManage.GotoNext("FrmFlawDeal", null, null, true);
                    break;
            }
        }

        private bool SaveFlawRejectReason()
        {
            flaw.RejectReason = tbRejectReason.Text;
            flawService.UpdateFlaw(flaw);

            return true;
        }

        private void btnPhoto_Click(object sender, EventArgs e)
        {
            //如果没有保存驳回原因，先保存
            SaveFlawRejectReason();

            if (flaw == null)
                return;

            LinkFileService linkFileService = new LinkFileService();
            LinkFile linkFile = linkFileService.TaskPicture(flaw.FlawID);
            if (linkFile == null)
                return;

            FormManage.GotoNext("FrmCamera", new object[] { "FrmFlawReject", linkFile }, new object[] { flaw}, false);

        }

        private void btnRecord_Click(object sender, EventArgs e)
        {
            //如果没有保存驳回原因，先保存
            SaveFlawRejectReason();

            if (flaw == null)
                return;

            FormManage.GotoNext("FrmRecording", new object[] { "FrmFlawReject", flaw.FlawID }, new object[] { flaw }, false);

        }





    }
}

